import Vue from "vue";
import Vuex from "vuex";
import { loginCellphone } from "@/api";

Vue.use(Vuex);

const userAbout = {
  state: {
    userInfo:{}
  },
  actions: {
    async userLogin({ commit }, { phone, password }) {
      let result = await loginCellphone(phone, password);
      if (result.data.code === 200) {
        commit("USERLOGIN",result.data);
        window.sessionStorage.setItem('token', result.data.token)
        window.sessionStorage.setItem('cookie', result.data.cookie)
        window.sessionStorage.setItem('isLogin', true)
        return "OK";
      }
      return new Error("fail");
    },
  },
  mutations: {
    USERLOGIN(state,data) {
      state.userInfo =  data
    },
  },
  getters: {},
};

export default new Vuex.Store({
  modules: {
    userAbout,
  },
});
